package everyday3;

/**
 * @Author: Siantar
 * @Date: 2023-07-17-11:31
 * @Description: 1.0
 */
public class T0415 {
    public String addStrings(String num1, String num2) {
        int n1 = num1.length(), n2 = num2.length();
        int m = Math.min(n1, n2);
        StringBuilder s = new StringBuilder();
        int carry = 0;
        for (int i = 0; i < m; i++) {
            int sum = carry + (num1.charAt(n1-i-1) - '0') + (num2.charAt(n2-i-1) - '0');
            s.insert(0, sum % 10);
            carry = sum / 10;
        }
        for (int i = m; i < n1; i++) {
            int sum = carry + (num1.charAt(n1-i-1) - '0');
            s.insert(0, sum % 10);
            carry = sum / 10;
        }
        for (int i = m; i < n2; i++) {
            int sum = carry + (num2.charAt(n2-i-1) - '0');
            s.insert(0, sum % 10);
            carry = sum / 10;
        }
        if (carry > 0) s.insert(0, carry);
        return s.toString();
    }
}
